package io.bitmax.exchange.core;

import android.provider.Settings;

import com.squareup.leakcanary.LeakCanary;

import io.bitmax.exchange.base.entity.DeviceInfo;
import io.bitmax.exchange.base.service.RetrofitService;
import io.bitmax.library.core.BaseCoreApplication;
import io.bitmax.library.utils.PackageUtils;
import io.bitmax.library.utils.ToastUtils;

/**
 * Created by gongdongyang on 2018/9/25.
 */

public class SystemConfig {

    private static  SystemConfig _instance;

    private SystemConfig (){

    }

    public static SystemConfig getInstance() {
        if(_instance == null){
            synchronized (SystemConfig.class){
                if(_instance==null){
                    _instance = new SystemConfig();
                }
            }
        }
        return _instance;
    }

    /**
     * 初始化 同步 异步
     */
    public void init(){
        syncInit();
        BMApplication.getInstance().getExecutor().execute(new Runnable() {
            @Override
            public void run() {
                asyncInit();
            }
        });
    }

    /**
     * 同步初始化操作
     */
    private void syncInit() {
        RetrofitService.init();
        ToastUtils.init(BaseCoreApplication.getInstance());
        initPhone();
    }

    /**
     * 异步初始化操作
     */
    private void asyncInit() {
        LeakCanary.install(BaseCoreApplication.getInstance());
    }

    private void initPhone() {
        DeviceInfo.mDeviceID = Settings.System.getString(
                BMApplication.getInstance().getContentResolver(),
                Settings.Secure.ANDROID_ID);

        DeviceInfo.mVersionID = PackageUtils.getVersionName(BMApplication.getInstance());
        DeviceInfo.mPhoneType = "Android";
        //DeviceInfo.mChannel = ChannelUtil.getChannel(BMApplication.getApplictionContext());
        DeviceInfo.mSource = "1";
    }


}
